package com.hckj.jianzhijia.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVUser;
import com.hckj.jianzhijia.utils.Data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 赵奇隆 on 2015-12-05.
 *
 */
public class NormalUser implements Parcelable {

    public static final String TABLE_NAME = "normalUser";

    private String email;
    private String name;
    private String username;//里边是手机号
    private boolean emailVerified;//邮箱是否已经验证
    private int userType ;
    private AVObject userInfo;
    private AVUser avUser;
    private int sex;//
    private int school;
    private String schoolName;
    private int city;
    private String cityName;
    private int province;
    private String provinceName;
    private String experience;
    private AVFile pic;
    private String qqNumber;//如果都加了qq，那么谁还去用我们的聊天呢，这个必须不显示！
    private String intention;
    private int[] intentionArray;
    private String birthDayString;
    private Date birthday;


    // TODO: 2015-12-06 用户表没有用指针进行链接，直接用的一个手机号作为连接了
    public NormalUser(AVUser avUser, AVObject userInfo) {

        this.avUser = avUser;
        this.userInfo = userInfo;
        this.email = avUser.getEmail();
        this.name = avUser.getString("name");
        this.username = avUser.getUsername();
        this.emailVerified = avUser.getBoolean("emailVerified");
        this.userType = avUser.getInt("userType");
        this.sex = userInfo.getInt("sex");
        this.school = userInfo.getInt("school");
        this.city = userInfo.getInt("city");
        this.province = userInfo.getInt("province");
        this.experience = userInfo.getString("experience");
        this.pic = userInfo.getAVFile("pic");
        this.qqNumber = userInfo.getString("qqNumber");
        this.intention = userInfo.getString("intention");
        this.birthDayString = userInfo.getString("birthday");
        //数据库里存储Array比较好，为了防止后期出现修改问题，现在用这个方式转换,使用‘|’符号进行分割也挺好的
        String[] tempStringArray = intention.split("/");
//      char[] tempStringArray = intention.toCharArray();
        this.intentionArray = new int[tempStringArray.length];
        for (int i = 0, j = tempStringArray.length; i < j; i++) {
            //将char数组转换成int数组
            this.intentionArray[i] = Integer.parseInt(tempStringArray[i]);
        }
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        try {
            birthday = sdf.parse(birthDayString);
        } catch (ParseException e) {
            e.printStackTrace();
        }


    }


    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getBirthDayString() {
        return birthDayString;
    }

    public void setBirthDayString(String birthDay) {
        this.birthDayString = birthDay;
    }

    public AVUser getAvUser() {
        return avUser;
    }

    public void setAvUser(AVUser avUser) {
        this.avUser = avUser;
    }

    public int getCity() {
        return city;
    }

    public void setCity(int city) {
        this.city = city;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isEmailVerified() {
        return emailVerified;
    }

    public void setEmailVerified(boolean emailVerified) {
        this.emailVerified = emailVerified;
    }

    public String getExperience() {
        return experience;
    }

    public void setExperience(String experience) {
        this.experience = experience;
    }

    public String getIntention() {
        return intention;
    }

    public void setIntention(String intention) {
        this.intention = intention;
    }

    public int[] getIntentionArray() {
        return intentionArray;
    }

    public void setIntentionArray(int[] intentionArray) {
        this.intentionArray = intentionArray;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public AVFile getPic() {
        return pic;
    }

    public void setPic(AVFile pic) {
        this.pic = pic;
    }

    public int getProvince() {
        return province;
    }

    public void setProvince(int province) {
        this.province = province;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getQqNumber() {
        return qqNumber;
    }

    public void setQqNumber(String qqNumber) {
        this.qqNumber = qqNumber;
    }

    public int getSchool() {
        return school;
    }

    public void setSchool(int school) {
        this.school = school;
    }

    public String getSchoolName() {
        return schoolName;
    }

    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public AVObject getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(AVObject userInfo) {
        this.userInfo = userInfo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getUserType() {
        return userType;
    }

    public void setUserType(int userType) {
        this.userType = userType;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        //修改数据，不需要修改外部
        dest.writeParcelable(avUser,flags);
        dest.writeParcelable(userInfo,flags);
        dest.writeString(schoolName);
        dest.writeString(cityName);
        dest.writeString(provinceName);

    }

    public static final Parcelable.Creator<NormalUser > CREATOR = new Parcelable.Creator<NormalUser >() {

        public NormalUser createFromParcel(Parcel source)
        {
            AVUser avUser  = source.readParcelable(AVUser.class.getClassLoader());
            AVObject avObject = source.readParcelable(AVObject.class.getClassLoader());
            String schoolName = source.readString();
            String cityName = source.readString();
            String provinceName = source.readString();
            NormalUser normalUser = new NormalUser(avUser, avObject);
            normalUser.setSchoolName(schoolName);
            normalUser.setCityName(cityName);
            normalUser.setProvinceName(provinceName);
            return normalUser;
        }

        public NormalUser [] newArray(int size) {
            return new NormalUser [size];
        }
    };
}
